layui.use('form', function () {
    var form = layui.form;
    form.verify({
        cusName: function (value) {
            var message = '';
            if (value.length < 1 || value.length > 15) {
                return '客户名称不得少于1字符或大于15字符';
            }
            $.ajax({
                url: 'jay/Customer/judgeName2',
                async: false,
                data: "cusName=" + value + "&id=" + $('#cId').val(),
                type: 'post',
                dataType: 'JSON',
                success: function (data) {
                    if (data.obj != null) {
                        message = "该用户已存在"
                    }
                }
            })
            if (message != '') {
                return message;
            }
        },
        address: function (value) {
            if (value.length < 1) {
                return '地址不能为空';
            }
        },
        phone: [/^1[3456789]\d{9}$/, '电话号码必须为1***********十一位数']
    });

    layui.form.on('submit(updat)', function (data) {
        var customer = { id: $("#cId").val(), cusName: $("#cusName").val(), address: $("#address").val(), phone: $("#phone").val() };
        $.ajax({
            url: 'jay/Customer/updCustomer',
            type: 'post',
            data: JSON.stringify(customer),
            contentType: 'application/json;charset=UTF-8',
            dataType: 'json',
            success: function (res) {
                // console.log();
                if (res.obj != null) {
                    alert("修改成功");
                } else {
                    alert("修改失败，请稍后再试!");
                }
                window.parent.location.reload();
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            }
        })
    })
});